package sensorLAN.UIServidor;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class VentanaClickDerecho extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3439387754066519966L;
	
	private JButton borrar, cerrar;
	private Border lineaNegra;
	private PanelTabla contenedor;
	
	public VentanaClickDerecho(Principal padre, PanelTabla contenedor, String texto) {
		super(padre,true);
		this.contenedor= contenedor;
		lineaNegra= BorderFactory.createLineBorder(Color.black);
		
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		
		this.getContentPane().setLayout(new BorderLayout());
		
		JPanel panel1= new JPanel(), panel2= new JPanel();
		panel1.setBorder(lineaNegra);
		panel2.setBorder(lineaNegra);
		
		JLabel etiqueta= new JLabel(texto);
		panel1.add(etiqueta);
		
		borrar= new JButton("Borrar");
		cerrar= new JButton("Cerrar");
		panel2.add(borrar);
		panel2.add(cerrar);
		
		this.add(panel1, BorderLayout.CENTER);
		this.add(panel2, BorderLayout.SOUTH);
	
		this.pack();
		this.setLocationRelativeTo(padre);
		
		manejarEventos();
	}

	private void manejarEventos() {
		System.err.println("Registrando oyente en ventana....");
		this.addKeyListener(new OyenteTeclasPresionadas(this));
		System.err.println("Se rregistro oyente en ventanaaaaaaaaaaaaaaaaaaaa");
		
		cerrar.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();				
			}			
		});
		
		borrar.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				contenedor.borrarFila();
				dispose();
			}			
		});
	}
}
